package com.guomao.demof;

import com.guomao.demof.Service;
import org.junit.Test;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

public class ProxyDemo {


    @Test
    public void method() {

        RealService rs = new RealService();

        ClassLoader loader = rs.getClass().getClassLoader();
        Class<?>[] interfaces = rs.getClass().getInterfaces();
        InvocationHandler proxy = new DynamicProxy(rs);
        Object o = Proxy.newProxyInstance(loader, interfaces, proxy);
        Service realProxy = (Service) o;
        realProxy.doSomething();
    }
}
